/*package com.utils.spring;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.http.MediaType;

import com.kyhd.lib.util.Constants;
import com.kyhd.lib.util.Util;
import com.kyhd.mogen.controller.model.ReqContext;
import com.kyhd.mogen.dao.model.User;
import com.kyhd.mogen.service.UserService;
import com.kyhd.mogen.util.ReqCtxUtil;

import lombok.extern.slf4j.Slf4j;

@Order(1)
@Slf4j
@Configuration
@WebFilter(filterName = "loginFilter1", urlPatterns = {
		"/mogen/api/*"
})
public class LoginFilter implements Filter {
	
	@Autowired
	UserService userService;

	public void init(FilterConfig filterConfig) throws ServletException {
	}

	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
			throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) servletRequest;
		HttpServletResponse response = (HttpServletResponse) servletResponse;
		try {
			boolean e = false;
			Cookie[] _cookies = request.getCookies();

			if (_cookies != null) {
				Cookie[] arg7 = _cookies;
				int arg8 = _cookies.length;

				for (int arg9 = 0; arg9 < arg8; ++arg9) {
					Cookie _ck = arg7[arg9];
					if (_ck.getName().equalsIgnoreCase(Constants.USER_LOGIN)) {
						e = true;
						ReqContext ctx = new ReqContext();

						User user = this.userService.getByID(Long.valueOf(_ck.getValue()));
						if(user==null) e = false;
						ctx.setName(user.getName());
						ctx.setOperateType(user.getOperateType());
						ctx.setUserID(user.getId());
						log.info("RequestContext ctx:{}", ctx);
						ReqCtxUtil.reqContext.set(ctx);
					}
				}
			}

			if (!e) {

				response.setContentType(MediaType.TEXT_PLAIN.toString());
				response.setStatus(403);
				response.getWriter().write("pls login");
			} else {

				filterChain.doFilter(servletRequest, servletResponse);
				ReqCtxUtil.reqContext.remove();
			}
		} catch (Exception arg12) {

			arg12.printStackTrace();
			log.error(Util.getExceptionStackTrace(arg12));
			ReqCtxUtil.reqContext.remove();
		}

	}

	public void destroy() {
	}
}*/